<?php

class Tweet {

	function __construct( $status ) {
		$this->date = $status->created_at;
		$this->messageid = $status->id;
		$this->message = $status->text;
		$this->source = $status->source;
		$this->truncated = $status->truncated;
		$this->replytostatus = $status->in_reply_to_status_id;
		$this->replytouser = $status->in_reply_to_user_id;
		$this->favorite = $status->favorited;

		self::parse();
	}

	public function parse() {
		$this->message = self::replaceUrl( $this->message );
		$this->message = self::replaceReplies( $this->message );
		$this->message = self::replaceHashes( $this->message );
	}

	public function replaceUrl( $message ) {
		return preg_replace( "(http://([a-zA-Z0-9./]+))", "<a href='http://\\1'>\\0</a>", $message );
	}

	public function replaceReplies( $message ) {
		return preg_replace( "(@([a-zA-Z0-9_]+))", "<a href='http://twitter.com/\\1'>\\0</a>", $message );
	}

	public function replaceHashes( $message ) {
		return preg_replace( "(#([a-zA-Z0-9_]+))", "<a href='http://twitter.com/#search?q=%23\\1'>\\0</a>", $message );
	}

	public function output() {
		return $this->message;
	}

}
